package com.beiye.drivertransport.adapter;

import android.content.Context;
import android.content.SharedPreferences;
import android.widget.CompoundButton;
import android.widget.RadioButton;

import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.bean.VehicleOrgTypeBean;

import java.util.List;

/**
 * Created by Administrator on 2018/4/25 0025.
 */

public class CarTypeApt extends CommonAdapter<VehicleOrgTypeBean.RowsBean> {
    private final List<VehicleOrgTypeBean.RowsBean> mList;
    private Context context;
    private RadioButton tv_cartype;
    // 标记用户当前选择
    private int index = -1;

    public CarTypeApt(Context context, List<VehicleOrgTypeBean.RowsBean> mList, int itemLayoutId) {
        super(context, mList, itemLayoutId);
        this.context = context;
        this.mList = mList;

    }



    @Override
    public void convert(ViewHolder holder, VehicleOrgTypeBean.RowsBean item, final int position) {
     //   RadioGroup   radioGroup = holder.getView(R.id.radio_car);
        tv_cartype = holder.getView(R.id.tv_car);
        tv_cartype.setText(mList.get(position).getFtName());

       /*if(mList.size()==1)
       {
           int ftId = mList.get(0).getFtId();
           SharedPreferences sp =context.getSharedPreferences("MessageEvent",
                   Context.MODE_PRIVATE);
           SharedPreferences.Editor editor = sp.edit();
           editor.putInt("ftId",ftId);
           editor.commit();
           tv_cartype.setChecked(true);
           tv_cartype.setBackgroundResource(R.drawable.carbtnpress);  //选中项背景
           tv_cartype.setTextColor(context.getResources().getColor(R.color.white_name) );

       }else if(mList.size()>1){
           tv_cartype.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
               @Override
               public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {

                   if (isChecked) {

                       String ftName = mList.get(position).getFtName();
                       int ftId = mList.get(position).getFtId();
                       SharedPreferences sp =context.getSharedPreferences("MessageEvent",
                               Context.MODE_PRIVATE);
                       SharedPreferences.Editor editor = sp.edit();
                       editor.putInt("ftId",ftId);
                       editor.commit();
                       index = position;
                       notifyDataSetChanged();
                   }
               }
           });
           if (index == position) {// 选中的条目和当前的条目是否相等
               tv_cartype.setChecked(true);
               tv_cartype.setBackgroundResource(R.drawable.carbtnpress);  //选中项背景
               tv_cartype.setTextColor(context.getResources().getColor(R.color.white_name) );
           } else {
               tv_cartype.setChecked(false);
               tv_cartype.setBackgroundResource(R.drawable.carbtn);  //其他项背景
               tv_cartype.setTextColor(context.getResources().getColor(R.color.project_blue) );
           }
       }*/

    }




}